package com.itheima_14;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class HashMapDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String line = sc.nextLine();

        // 无排序
//        HashMap<Character, Integer> map = new HashMap<Character, Integer>();
        // 排序
        TreeMap<Character, Integer> map = new TreeMap<Character, Integer>();

        for (int i = 0; i < line.length(); i++) {
            char key = line.charAt(i);

            Integer value = map.get(key);
            if (value == null) {
                map.put(key, 1);
            } else {
                value++;
                map.put(key, value);
            }
        }

        StringBuilder stringBuilder = new StringBuilder();
        Set<Character> characters = map.keySet();
        for (Character character : characters) {
            Integer integer = map.get(character);
            stringBuilder.append(character).append("(").append(integer).append(")");
        }

        String s = stringBuilder.toString();
        System.out.println(s);
    }
}
